package com.hospital.hospitalsystem.utils;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * @author qiancheng@cqxyy.net
 * @date 2023/2/24
 */
public class TimeUtils {

    // 获得当前日期与本周日相差的天数
    public static int getMondayPlus(Date gmtCreate) {
        Calendar cd = Calendar.getInstance();
        cd.setTime(gmtCreate);
        // 获得今天是一周的第几天，星期日是第一天，星期一是第二天......
        int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK) - 1;
        if(dayOfWeek == 0){
            return -7;
        }else{
            return -dayOfWeek;
        }
    }

    // 获得下周星期的日期
    public static Date getNextWeekDate(Date gmtCreate,int offer) {
        int mondayPlus = getMondayPlus(gmtCreate) + offer;
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7);
        Date day = currentDate.getTime();
        return day;
    }
}
